var app = new Vue({
    el: '#app',
    data: {
		onLoading:true,//页面加载中
		eqDetails:{}
    },
    created:function(){
    	var that = this;
    	if ($.getPara("userId") != "") {
			var userId = $.getPara("userId");
			this.userId = userId;
			//缓存用户ID
			$.setStorage("userId", userId);
		} else {
			if ($.getStorage("userId") && $.getStorage("userId") != "") {
				var userId = parseInt($.getStorage("userId"));
				this.userId = userId;
			}
		}
    	that.getDetails();
	},
    methods:{
 			//获取详情
 			getDetails(id){
				var that =this;
 				var id = $.getPara('id');
 				var userId = getUserId(true);
 				$.ajax({
 					type:"GET",
 					url: "/api/device/detail",
 					dataType: 'json',
 					data:{
 						id:id,
 						userId:userId
 					},
 					success:function(res){
						res.data.banner_img = JSON.parse(res.data.banner_img);
						that.eqDetails = res.data;
						// console.log(that.eqDetails,"数据");
				    	setTimeout(function(){
					    	var swiper = new Swiper('.swiper-container', {
						      autoplay : 3000,
						      loop: true,
						      pagination : '.swiper-pagination',
						      autoplayDisableOnInteraction : true,
						    }); 
						},1)
						that.onLoading = false;
 					},
 				})
 			},
 			//收藏
			chooseCollect(){
				//添加一个强制登录以获取userId
				// if(this.userId && this.userId > 0){//获取到userId字段内容并且用户id>0已登录
					var  that = this;
					var userId = getUserId(true);
					var objectId = $.getPara('id');
					if(userId != false ){
						$.ajax({
							type:"POST",
							url: "/api/collect/collect",
							dataType: 'json',
							data:{
								type:4,//1资讯，2供应，3求购，4设备，5印厂
								objectId:objectId,
								userId:userId,
							},
							success:function(res){
								if(res.code == 200){
									$.toast("收藏成功","text");
									that.$set(that.eqDetails,"is_collect", 1)
								}
							},
						})	
					}
				// }else{
				// 	//用户未登录
				// 	if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){ //判断iPhone|iPad|iPod|iOS
				// 		//默认为iOS系统   
				// 		window.webkit.messageHandlers.appLogin.postMessage(null);
				// 	}else {
				// 		//pc
				// 		alert("PC浏览器-appLogin");
				// 	};
				// }
 			},
 			//取消收藏
			chanceCollect(){
				//添加一个强制登录以获取userId
				//获取到userId字段内容并且用户id>0已登录   
            	if(this.userId && this.userId > 0){
					var  that = this;
					var userId = getUserId(true);
					var objectId = $.getPara('id');
					if(userId != false ){
						$.ajax({
							type:"POST",
							url: "/api/collect/cancelCollect",
							dataType: 'json',
							data:{
								type:4,//1资讯，2供应，3求购，4设备，5印厂
								objectId:objectId,
								userId:userId,
							},
							success:function(res){
								if(res.code == 200){
									$.toast("取消收藏成功", "text");
									that.$set(that.eqDetails,"is_collect", 0)
								}
							},
						})	
					}
				}else{
					//用户未登录
					if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){ //判断iPhone|iPad|iPod|iOS
						//默认为iOS系统   
						window.webkit.messageHandlers.appLogin.postMessage(null);
					}else {
						//pc
						alert("PC浏览器-appLogin");
					};
				}
 			},
 			//路径跳转-在线留言
	        gotomessage(id) {
				//添加一个强制登录以获取userId
				//获取到userId字段内容并且用户id>0已登录   
            	if(this.userId && this.userId > 0){
					var para = {};
					para.title = "在线留言";
					para.type = "equEvaluating";
					para.url = '/PageClassify/html/LeaveWords/liuyan.html?pressId='+id;
					if (this.userId > 0) {
						para.url = '/PageClassify/html/LeaveWords/liuyan.html?pressId='+id + "&userId=" + this.userId;
					}
					//window.location.href =para.url;
					if (/(Android)/i.test(navigator.userAgent)) { //判断Android
						//是android系统
						// alert("Android系统");
						jsAndroid.appPush(JSON.stringify(para))
					} else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
						//默认为iOS系统
						window.webkit.messageHandlers.appPush.postMessage(para);
					} else {
						//pc
						window.location.href = para.url;
						alert("请使用移动设备！");
					};
				}else{
					//用户未登录
					if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){ //判断iPhone|iPad|iPod|iOS
						//默认为iOS系统   
						window.webkit.messageHandlers.appLogin.postMessage(null);
					}else {
						//pc
						alert("PC浏览器-appLogin");
					};
				}
	        },
	        //拨打电话
	        toMobile(phone) {
	            var para = {};
	            para.mobile = phone;
	            if (/(Android)/i.test(navigator.userAgent)) { //判断Android
	                //是android系统
	                // alert("Android系统");
	                jsAndroid.appMobile(JSON.stringify(para))
	            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { 
	            	//判断iPhone|iPad|iPod|iOS
	                //默认为iOS系统
	                window.webkit.messageHandlers.appMobile.postMessage(para);
	            } else {
	                //pc
	                window.location.href = para.url;
	                alert("请使用移动设备！");
	            };
	        },
	   }	
  })

